package com.jade.linkong.controller;

import com.jade.common.annotation.Log;
import com.jade.common.core.controller.BaseController;
import com.jade.common.core.domain.AjaxResult;
import com.jade.common.core.domain.Ztree;
import com.jade.common.enums.BusinessType;
import com.jade.common.utils.StringUtils;
import com.jade.common.utils.poi.ExcelUtil;
import com.jade.linkong.domain.LkProjectTag;
import com.jade.linkong.service.ILkProjectTagService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目标签Controller
 * 
 * @author jade
 * @date 2020-08-05
 */
@Controller
@RequestMapping("/linkong/projectTag")
public class LkProjectTagController extends BaseController
{
    private String prefix = "linkong/projectTag";

    @Autowired
    private ILkProjectTagService lkProjectTagService;

    @RequiresPermissions("linkong:projectTag:view")
    @GetMapping()
    public String projectTag()
    {
        return prefix + "/projectTag";
    }

    /**
     * 查询项目标签树列表
     */
    @RequiresPermissions("linkong:projectTag:list")
    @PostMapping("/list")
    @ResponseBody
    public List<LkProjectTag> list(LkProjectTag lkProjectTag)
    {
        List<LkProjectTag> list = lkProjectTagService.selectLkProjectTagList(lkProjectTag);
        return list;
    }

    /**
     * 导出项目标签列表
     */
    @RequiresPermissions("linkong:projectTag:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LkProjectTag lkProjectTag)
    {
        List<LkProjectTag> list = lkProjectTagService.selectLkProjectTagList(lkProjectTag);
        ExcelUtil<LkProjectTag> util = new ExcelUtil<LkProjectTag>(LkProjectTag.class);
        return util.exportExcel(list, "projectTag");
    }

    /**
     * 新增项目标签
     */
    @GetMapping(value = { "/add/{tabId}", "/add/" })
    public String add(@PathVariable(value = "tabId", required = false) Long tabId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(tabId))
        {
            mmap.put("lkProjectTag", lkProjectTagService.selectLkProjectTagById(tabId));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存项目标签
     */
    @RequiresPermissions("linkong:projectTag:add")
    @Log(title = "项目标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LkProjectTag lkProjectTag)
    {
        return toAjax(lkProjectTagService.insertLkProjectTag(lkProjectTag));
    }

    /**
     * 修改项目标签
     */
    @GetMapping("/edit/{tabId}")
    public String edit(@PathVariable("tabId") Long tabId, ModelMap mmap)
    {
        LkProjectTag lkProjectTag = lkProjectTagService.selectLkProjectTagById(tabId);
        mmap.put("lkProjectTag", lkProjectTag);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目标签
     */
    @RequiresPermissions("linkong:projectTag:edit")
    @Log(title = "项目标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LkProjectTag lkProjectTag)
    {
        return toAjax(lkProjectTagService.updateLkProjectTag(lkProjectTag));
    }

    /**
     * 删除
     */
    @RequiresPermissions("linkong:projectTag:remove")
    @Log(title = "项目标签", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{tabId}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("tabId") Long tabId)
    {
        return toAjax(lkProjectTagService.deleteLkProjectTagById(tabId));
    }

    /**
     * 选择项目标签树
     */
    @GetMapping(value = { "/selectProjectTagTree/{tabId}", "/selectProjectTagTree/" })
    public String selectProjectTagTree(@PathVariable(value = "tabId", required = false) Long tabId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(tabId))
        {
            mmap.put("lkProjectTag", lkProjectTagService.selectLkProjectTagById(tabId));
        }
        return prefix + "/tree";
    }

    /**
     * 加载项目标签树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = lkProjectTagService.selectLkProjectTagTree();
        return ztrees;
    }
}
